home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / IPC / Msg2PPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-05  |  3.0 KB  |  149 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <utility/tagitem.h>
  6. #include <powerup/ppclib/interface.h>
  7. #include <powerup/ppclib/message.h>
  8. #include <powerup/ppclib/tasks.h>
  9. #include <powerup/gcclib/powerup_protos.h>
  10.  
  11. #define TEXT    "Text sent by PPC processor\n"
  12. #define    DEBUG    0
  13.  
  14. struct StartupData
  15. {
  16.     void    *MsgPort;
  17. };
  18.  
  19. BPTR    MyFile;
  20.  
  21.  
  22. int    main(void)
  23. {
  24. struct TagItem        MyTags[10];
  25. struct StartupData    *StartupData;
  26. void            *PPCPort;
  27. void            *ReplyPort;
  28. void            *PPCMsg;
  29. void            *M68kMsg;
  30. void            *Body;
  31. ULONG            result;
  32.  
  33.   StartupData    =(struct StartupData *) PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA);
  34.  
  35. #if DEBUG
  36.   if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
  37.   {
  38. #endif
  39.  
  40.     if (PPCPort=(void*) PPCGetTaskAttr(PPCTASKTAG_MSGPORT))
  41.     {
  42. #if DEBUG
  43.       PPCfprintf(MyFile,"Waiting for M68k message\n");
  44. #endif
  45.       PPCWaitPort(PPCPort);
  46.  
  47. #if DEBUG
  48.       PPCfprintf(MyFile,"Getting message\n");
  49. #endif
  50.       if (M68kMsg = PPCGetMessage(PPCPort))
  51.       {
  52. #if DEBUG
  53.         PPCfprintf(MyFile,"Message: ");
  54.         PPCfprintf(MyFile,(char*) PPCGetMessageAttr(M68kMsg, PPCMSGTAG_DATA));
  55. #endif
  56.         PPCReplyMessage(M68kMsg);
  57.       }
  58.       else
  59.       {
  60. #if DEBUG
  61.         PPCfprintf(MyFile,"Did not get m68k msg\n");
  62. #endif
  63.       }
  64.  
  65. #if DEBUG
  66.       PPCfprintf(MyFile,"Allocating memory for message body\n");
  67. #endif
  68.       if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  69.       {
  70. #if DEBUG
  71.         PPCfprintf(MyFile,"Creating reply port\n");
  72. #endif
  73.         MyTags[0].ti_Tag = TAG_DONE;
  74.         if (ReplyPort = PPCCreatePort(MyTags))
  75.         {
  76. #if DEBUG
  77.           PPCfprintf(MyFile,"Creating message\n");
  78. #endif
  79.           if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  80.           {
  81. #if DEBUG
  82.             PPCfprintf(MyFile,"Sending message\n");
  83. #endif
  84.             strcpy(Body, TEXT);
  85.  
  86.             PPCSendMessage(StartupData->MsgPort,
  87.                            PPCMsg,
  88.                            Body,
  89.                            sizeof(TEXT),
  90.                            0x87654321);
  91.  
  92. #if DEBUG
  93.             PPCfprintf(MyFile,"Waiting for reply\n");
  94. #endif
  95.             PPCWaitPort(ReplyPort);
  96.  
  97. #if DEBUG
  98.             PPCfprintf(MyFile,"Deleting message\n");
  99. #endif
  100.             PPCDeleteMessage(PPCMsg);
  101.  
  102.           }
  103.           else
  104.           {
  105. #if DEBUG
  106.             PPCfprintf(MyFile,"Could not create ppc msg\n");
  107. #endif
  108.           }
  109.  
  110. #if DEBUG
  111.           PPCfprintf(MyFile,"Deleting reply port\n");
  112. #endif
  113.           while (PPCDeletePort(ReplyPort) == FALSE);
  114.  
  115.         }
  116.         else
  117.         {
  118. #if DEBUG
  119.           PPCfprintf(MyFile,"Could not create reply port\n");
  120. #endif
  121.         }
  122.  
  123. #if DEBUG
  124.         PPCfprintf(MyFile,"Freeing message body memory\n");
  125. #endif
  126.         PPCFreeVec(Body);
  127.       }
  128.       else
  129.       {
  130. #if DEBUG
  131.         PPCfprintf(MyFile,"Could not alloc mem for msg body\n");
  132. #endif
  133.       }
  134.     }
  135.     else
  136.     {
  137. #if DEBUG
  138.       PPCfprintf(MyFile,"Could not find the PPC Task`s msgport\n");
  139. #endif
  140.     }
  141.  
  142. #if DEBUG
  143.     PPCfprintf(MyFile,"Closing output\n");
  144.     PPCClose(MyFile);
  145.   }
  146. #endif
  147. }
  148.  
  149.